@@ -1 +0,0 @@ |
||
1 |
-Lensman |
@@ -5,7 +5,7 @@ |
||
5 | 5 |
<GradleProjectSettings> |
6 | 6 |
<option name="distributionType" value="LOCAL" /> |
7 | 7 |
<option name="externalProjectPath" value="$PROJECT_DIR$" /> |
8 |
- <option name="gradleHome" value="C:\Android\Studio\gradle\gradle-2.14.1" /> |
|
8 |
+ <option name="gradleHome" value="C:\Android\android-studio\gradle\gradle-2.14.1" /> |
|
9 | 9 |
<option name="modules"> |
10 | 10 |
<set> |
11 | 11 |
<option value="$PROJECT_DIR$" /> |
@@ -14,14 +14,7 @@ |
||
14 | 14 |
<option value="$PROJECT_DIR$/views" /> |
15 | 15 |
</set> |
16 | 16 |
</option> |
17 |
- <option name="myModules"> |
|
18 |
- <set> |
|
19 |
- <option value="$PROJECT_DIR$" /> |
|
20 |
- <option value="$PROJECT_DIR$/app" /> |
|
21 |
- <option value="$PROJECT_DIR$/common" /> |
|
22 |
- <option value="$PROJECT_DIR$/views" /> |
|
23 |
- </set> |
|
24 |
- </option> |
|
17 |
+ <option name="resolveModulePerSourceSet" value="false" /> |
|
25 | 18 |
</GradleProjectSettings> |
26 | 19 |
</option> |
27 | 20 |
</component> |
@@ -3,8 +3,12 @@ |
||
3 | 3 |
<component name="ProjectModuleManager"> |
4 | 4 |
<modules> |
5 | 5 |
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
6 |
+ <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
|
7 |
+ <module fileurl="file://$PROJECT_DIR$/common/common.iml" filepath="$PROJECT_DIR$/common/common.iml" /> |
|
6 | 8 |
<module fileurl="file://$PROJECT_DIR$/common/common.iml" filepath="$PROJECT_DIR$/common/common.iml" /> |
7 | 9 |
<module fileurl="file://$PROJECT_DIR$/lensman_ssh.iml" filepath="$PROJECT_DIR$/lensman_ssh.iml" /> |
10 |
+ <module fileurl="file://$PROJECT_DIR$/lensman_ssh.iml" filepath="$PROJECT_DIR$/lensman_ssh.iml" /> |
|
11 |
+ <module fileurl="file://$PROJECT_DIR$/views/views.iml" filepath="$PROJECT_DIR$/views/views.iml" /> |
|
8 | 12 |
<module fileurl="file://$PROJECT_DIR$/views/views.iml" filepath="$PROJECT_DIR$/views/views.iml" /> |
9 | 13 |
</modules> |
10 | 14 |
</component> |
@@ -56,6 +56,14 @@ public class Preferences { |
||
56 | 56 |
mPrefs.edit().putString("wxcode",wxCode).commit(); |
57 | 57 |
} |
58 | 58 |
|
59 |
+ public void setPrinterMac(String macAdr){ |
|
60 |
+ mPrefs.edit().putString("mac",macAdr).commit(); |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ public String getPrinterMac(){ |
|
64 |
+ return mPrefs.getString("mac",NullStr); |
|
65 |
+ } |
|
66 |
+ |
|
59 | 67 |
public void clearPrefs(){ |
60 | 68 |
mPrefs.edit().clear().commit(); |
61 | 69 |
} |
@@ -11,6 +11,7 @@ import android.widget.TextView; |
||
11 | 11 |
import java.util.ArrayList; |
12 | 12 |
|
13 | 13 |
import ai.pai.lensman.R; |
14 |
+import ai.pai.lensman.db.Preferences; |
|
14 | 15 |
|
15 | 16 |
/** |
16 | 17 |
* Created by chengzhenyu on 2016/9/1. |
@@ -78,7 +79,11 @@ public class BluetoothDeviceListAdapter extends BaseAdapter { |
||
78 | 79 |
BluetoothDevice device = deviceList.get(position); |
79 | 80 |
holder.deviceName.setText(device.getName()); |
80 | 81 |
holder.deviceMac.setText(device.getAddress()); |
81 |
- holder.deviceStatus.setText(R.string.click_to_connect); |
|
82 |
+ if(device.getAddress().equals(Preferences.getInstance().getPrinterMac())){ |
|
83 |
+ holder.deviceStatus.setText(R.string.click_to_connect); |
|
84 |
+ }else{ |
|
85 |
+ holder.deviceStatus.setText(""); |
|
86 |
+ } |
|
82 | 87 |
return convertView; |
83 | 88 |
} |
84 | 89 |
|
@@ -25,6 +25,7 @@ import java.util.Set; |
||
25 | 25 |
|
26 | 26 |
import ai.pai.lensman.App; |
27 | 27 |
import ai.pai.lensman.R; |
28 |
+import ai.pai.lensman.db.Preferences; |
|
28 | 29 |
|
29 | 30 |
/** |
30 | 31 |
* Created by chengzhenyu on 2016/9/1. |
@@ -168,10 +169,14 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter |
||
168 | 169 |
} |
169 | 170 |
try { |
170 | 171 |
int code = mGpService.openPort(0, PortParameters.BLUETOOTH, device.getAddress(), 0); |
172 |
+ if(code==0){ |
|
173 |
+ Preferences.getInstance().setPrinterMac(device.getAddress()); |
|
174 |
+ } |
|
171 | 175 |
LogHelper.d("czy111","open port return code ="+code); |
172 | 176 |
} catch (Exception e) { |
173 | 177 |
view.showToast(context.getString(R.string.printer_port_open_fail)); |
174 | 178 |
} |
179 |
+ |
|
175 | 180 |
} |
176 | 181 |
|
177 | 182 |
@Override |
@@ -5,18 +5,22 @@ import android.content.Context; |
||
5 | 5 |
import android.content.Intent; |
6 | 6 |
import android.content.ServiceConnection; |
7 | 7 |
import android.os.IBinder; |
8 |
-import android.os.RemoteException; |
|
8 |
+import android.text.TextUtils; |
|
9 | 9 |
import android.util.Base64; |
10 | 10 |
import android.util.Log; |
11 | 11 |
|
12 |
+import com.android.common.utils.LogHelper; |
|
12 | 13 |
import com.gprinter.aidl.GpService; |
13 | 14 |
import com.gprinter.command.EscCommand; |
14 | 15 |
import com.gprinter.command.GpCom; |
16 |
+import com.gprinter.io.PortParameters; |
|
15 | 17 |
import com.gprinter.service.GpPrintService; |
16 | 18 |
|
17 | 19 |
import org.apache.commons.lang.ArrayUtils; |
18 | 20 |
|
21 |
+import java.text.SimpleDateFormat; |
|
19 | 22 |
import java.util.ArrayList; |
23 |
+import java.util.Date; |
|
20 | 24 |
import java.util.Vector; |
21 | 25 |
|
22 | 26 |
import ai.pai.lensman.App; |
@@ -24,6 +28,7 @@ import ai.pai.lensman.R; |
||
24 | 28 |
import ai.pai.lensman.bean.PhotoBean; |
25 | 29 |
import ai.pai.lensman.bean.SessionBean; |
26 | 30 |
import ai.pai.lensman.db.DBService; |
31 |
+import ai.pai.lensman.db.Preferences; |
|
27 | 32 |
import ai.pai.lensman.service.UploadService; |
28 | 33 |
|
29 | 34 |
|
@@ -108,28 +113,37 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
108 | 113 |
|
109 | 114 |
@Override |
110 | 115 |
public void printQR() { |
116 |
+ if(TextUtils.isEmpty(Preferences.getInstance().getPrinterMac())){ |
|
117 |
+ sessionView.showToast(App.getAppContext().getString(R.string.not_set_printer_yet)); |
|
118 |
+ return; |
|
119 |
+ } |
|
120 |
+ checkPrinter(); |
|
111 | 121 |
EscCommand esc = new EscCommand(); |
112 | 122 |
esc.addPrintAndFeedLines((byte) 3); |
113 | 123 |
esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中 |
114 | 124 |
esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽 |
115 |
- esc.addText("Sample\n"); // 打印文字 |
|
125 |
+ esc.addText("拍爱\n"); // 打印文字 |
|
116 | 126 |
esc.addPrintAndLineFeed(); |
117 | 127 |
|
118 | 128 |
/*打印文字*/ |
119 | 129 |
esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽 |
120 | 130 |
esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐 |
121 |
- esc.addText("Welcome to use Paiai!\n"); // 打印文字 |
|
131 |
+ esc.addText("欢迎使用拍爱!\n"); // 打印文字 |
|
122 | 132 |
|
123 | 133 |
/*QRCode命令打印 |
124 | 134 |
此命令只在支持QRCode命令打印的机型才能使用。 |
125 | 135 |
在不支持二维码指令打印的机型上,则需要发送二维条码图片 |
126 | 136 |
*/ |
127 |
- esc.addText("Print QRcode\n"); // 打印文字 |
|
137 |
+ esc.addText("Print QRCode\n"); // 打印文字 |
|
138 |
+ esc.addPrintAndFeedLines((byte) 3); |
|
128 | 139 |
esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级 |
129 |
- esc.addSelectSizeOfModuleForQRCode((byte) 3);//设置qrcode模块大小 |
|
140 |
+ esc.addSelectSizeOfModuleForQRCode((byte)10);//设置qrcode模块大小 |
|
130 | 141 |
esc.addStoreQRCodeData(sessionBean.sessionId);//设置qrcode内容 |
142 |
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐 |
|
131 | 143 |
esc.addPrintQRCode();//打印QRCode |
132 |
- esc.addPrintAndLineFeed(); |
|
144 |
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐 |
|
145 |
+ esc.addText("拍摄日期 "+new SimpleDateFormat("yy/MM/dd HH:mm").format(new Date())); |
|
146 |
+ esc.addPrintAndFeedLines((byte) 3); |
|
133 | 147 |
|
134 | 148 |
Vector<Byte> datas = esc.getCommand(); //发送数据 |
135 | 149 |
Byte[] Bytes = datas.toArray(new Byte[datas.size()]); |
@@ -147,6 +161,34 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
147 | 161 |
} |
148 | 162 |
} |
149 | 163 |
|
164 |
+ private void checkPrinter(){ |
|
165 |
+ sessionView.showToast(App.getAppContext().getString(R.string.connecting)); |
|
166 |
+ try{ |
|
167 |
+ int status = mGpService.queryPrinterStatus(0, 10000); |
|
168 |
+ if (status != GpCom.STATE_NO_ERR) { |
|
169 |
+ connectPrinter(); |
|
170 |
+ } |
|
171 |
+ }catch (Exception e){ |
|
172 |
+ sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer)); |
|
173 |
+ return; |
|
174 |
+ } |
|
175 |
+ printQR(); |
|
176 |
+ } |
|
177 |
+ |
|
178 |
+ public void connectPrinter() { |
|
179 |
+ if(mGpService==null){ |
|
180 |
+ sessionView.showToast(App.getAppContext().getString(R.string.printer_service_boot_fail)); |
|
181 |
+ return; |
|
182 |
+ } |
|
183 |
+ try { |
|
184 |
+ int code = mGpService.openPort(0, PortParameters.BLUETOOTH, Preferences.getInstance().getPrinterMac(), 0); |
|
185 |
+ LogHelper.d("czy111","open port return code ="+code); |
|
186 |
+ } catch (Exception e) { |
|
187 |
+ sessionView.showToast(App.getAppContext().getString(R.string.printer_port_open_fail)); |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ } |
|
191 |
+ |
|
150 | 192 |
private void startAndBindPrintService() { |
151 | 193 |
Intent intent = new Intent(App.getAppContext(), GpPrintService.class); |
152 | 194 |
App.getAppContext().startService(intent); |
@@ -110,4 +110,6 @@ |
||
110 | 110 |
<string name="printer_status_query_fail">打印机状态查询失败</string> |
111 | 111 |
|
112 | 112 |
<string name="printer_service_boot_fail">打印机服务连接失败,请退出应用重试</string> |
113 |
+ |
|
114 |
+ <string name="not_set_printer_yet">尚未设置打印机,去设置</string> |
|
113 | 115 |
</resources> |
@@ -5,7 +5,7 @@ buildscript { |
||
5 | 5 |
jcenter() |
6 | 6 |
} |
7 | 7 |
dependencies { |
8 |
- classpath 'com.android.tools.build:gradle:2.1.3' |
|
8 |
+ classpath 'com.android.tools.build:gradle:2.2.0-rc1' |
|
9 | 9 |
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' |
10 | 10 |
// NOTE: Do not place your application dependencies here; they belong |
11 | 11 |
// in the individual module build.gradle files |